package com.googlecode.marrowboy.it;

import java.io.File;

import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
import org.junit.Test;

public class JavaAgentIT extends AbstractITClass{

    @Test
    public void javaAgentIt() throws Exception{
        
        File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/java-agent-it");

        Verifier verifier = new Verifier(testDir.getAbsolutePath());
        this.executeGoal(verifier, "test");
        verifier.verifyErrorFreeLog();
        verifier.resetStreams();
        
        checkMavenStdOut(testDir);
        
        File reportFile = new File(testDir, "target/marrowboy/report.txt");

        assertFileContains(reportFile, "Simple test");
        assertFileContains(reportFile, "Simple method");
        assertFileContains(reportFile, "Maths works");

        assertFileContains(reportFile, "without any reason");
    }

    private void checkMavenStdOut(File testDir) {
        File logFile = new File(testDir, "log.txt");
        assertFileContains(logFile, "monkey-patch");
    }
    
}
